package com.teamcenter.rac.massupdate.model;

import java.util.List;

import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;

import com.teamcenter.rac.massupdate.providers.PropertySourceLabelProvider;
import com.teamcenter.rac.util.Registry;
@SuppressWarnings({"unused","rawtypes","unchecked"})
public class ImpactedPart extends AbstractWrappedPropertySource {
	public static final String ITEM_REV_PROP_RELEASE_STATUS = "release_status_list";
	public static final String PROP_COMMENT = "comment";
	public static final String PROP_IMPACTED = "impacted";
	public static final String PROP_SELECTED = "selected";
	public static final String PROP_UPDATABLE = "updatable";
	private static final int NUM_LOCAL_PROP = 4;
	private final Registry m_registryFromUtil = Registry.getRegistry("com.teamcenter.rac.util.util");

	public ImpactedPart() {
		super(4);
		this.m_localPropNames.add("impacted");
		this.m_localPropNames.add("selected");
		this.m_localPropNames.add("comment");
		this.m_localPropNames.add("updatable");
		this.m_propertyValueMap.put("selected", Boolean.FALSE);
	}

	public ImpactedPart(IPropertySource paramIPropertySource) {
		this();
		setImpacted(paramIPropertySource);
	}

	public String getComment() {
		return (String) getPropertyValue("comment");
	}

	public IPropertySource getImpacted() {
		return (IPropertySource) getPropertyValue("impacted");
	}

	public IPropertyDescriptor[] getPropertyDescriptors() {
		if (this.m_propertyDescriptors == null) {
			List localList = getWrappedPropertyDescriptors(4);
			PropertyDescriptor localPropertyDescriptor1 = new PropertyDescriptor("impacted",
					Messages.ImpactedPart_Prop_ImpactedPart);
			PropertyDescriptor localPropertyDescriptor2 = new PropertyDescriptor("selected",
					Messages.ImpactedPart_Prop_Selected);
			PropertyDescriptor localPropertyDescriptor3 = new PropertyDescriptor("comment",
					Messages.ImpactedPart_Prop_Status);
			PropertyDescriptor localPropertyDescriptor4 = new PropertyDescriptor("updatable",
					Messages.ImpactedPart_Prop_Updateable);
			localPropertyDescriptor1.setLabelProvider(new PropertySourceLabelProvider("impacted"));
			localPropertyDescriptor2.setLabelProvider(new IC_SelectedLabelProvider("selected"));
			localPropertyDescriptor3.setLabelProvider(new PropertySourceLabelProvider("comment"));
			localPropertyDescriptor4.setLabelProvider(new PropertySourceLabelProvider("updatable"));
			localList.add(localPropertyDescriptor1);
			localList.add(localPropertyDescriptor2);
			localList.add(localPropertyDescriptor3);
			localList.add(localPropertyDescriptor4);
			this.m_propertyDescriptors = ((IPropertyDescriptor[]) localList
					.toArray(new IPropertyDescriptor[localList.size()]));
		}
		return this.m_propertyDescriptors;
	}

	public boolean isSelected() {
		return getPropertyValueAsBoolean("selected");
	}

	public boolean isUpdatable() {
		return getPropertyValueAsBoolean("updatable");
	}

	public void setComment(String paramString) {
		updateAndAnnounceProperty("comment", paramString);
	}

	public void setImpacted(IPropertySource paramIPropertySource) {
		setWrappedPropertySource(paramIPropertySource);
		updateAndAnnounceProperty("impacted", paramIPropertySource);
	}

	public void setSelected(boolean paramBoolean) {
		boolean bool = isSelected();
		if (bool != paramBoolean) {
			updateAndAnnounceProperty("selected", Boolean.valueOf(paramBoolean));
		}
	}

	public void setUpdatable(boolean paramBoolean) {
		updateAndAnnounceProperty("updatable", Boolean.valueOf(paramBoolean));
	}

	public IPropertySource getWrappedPropertySource() {
		return super.getWrappedPropertySource();
	}

	private class IC_SelectedLabelProvider extends PropertySourceLabelProvider {
		public IC_SelectedLabelProvider(String paramString) {
			super(paramString);
		}

		public Image getImage(Object paramObject) {
			if ((paramObject instanceof ImpactedPart)) {
				ImpactedPart localImpactedPart = (ImpactedPart) paramObject;
				if (localImpactedPart.isUpdatable()) {
					if (localImpactedPart.isSelected()) {
						return ImpactedPart.this.m_registryFromUtil.getImage("checked.ICON");
					}
					return ImpactedPart.this.m_registryFromUtil.getImage("unChecked.ICON");
				}
			}
			return null;
		}

		public String getText(Object paramObject) {
			if ((paramObject instanceof ImpactedPart)) {
				ImpactedPart localImpactedPart = (ImpactedPart) paramObject;
				if (localImpactedPart.isUpdatable()) {
					return super.getText(paramObject);
				}
			}
			return null;
		}
	}
}
